package com.just.gameapp.controller;

import com.just.gameapp.entity.Game;
import com.just.gameapp.service.GameService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zyr
 * @date 2024/6/18 下午3:07
 * @Description
 */
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/games")
public class GameController {
    @Resource
    private GameService gameService;

    @GetMapping("/list")
    public List<Game> getGameList() {
        return gameService.list();
    }

    @PostMapping("/add")
    public Object addGame(@ModelAttribute Game game) {
        return gameService.save(game);
    }

    @DeleteMapping("/delete/{gameId}")
    public Object deleteGame(@PathVariable Integer gameId) {
        return gameService.removeById(gameId);
    }

    @PutMapping("/update")
    public Object updateGame(@ModelAttribute Game game) {
        return gameService.updateById(game);
    }
    @GetMapping("/search") // 游戏名查询路径参数为param
    public List<Game> searchGame(@ModelAttribute("param") String gameName) {
        return gameService.searchGame(gameName);
    }
    @PostMapping("/search") // 查询路径参数为param
    public List<Game> searchGamePost(@ModelAttribute("param") String gameName) {
        return gameService.searchGame(gameName);
    }
}
